f3671b
@@ -165,7 +165,7 @@
public class BindyCsvDataFormat extends BindyAbstractDataFormat {
 
                 // Split the CSV record according to the separator defined in
                 // annotated class @CSVRecord
-                String[] tokens = line.split(separator, -1);
+                String[] tokens = line.split(separator, factory.getAutospanLine() ? factory.getMaxpos() : -1);
                 List<String> result = Arrays.asList(tokens);
                 // must unquote tokens before use
                 result = unquoteTokens(result, separator, quote);
@@ -177,10 +177,6 @@
public class BindyCsvDataFormat extends BindyAbstractDataFormat {
                         LOG.debug("Size of the record splitted : {}", result.size());
                     }
 
-                    if (factory.getAutospanLine()) {
-                        result = autospanLine(result, factory.getMaxpos(), separator);
-                    }
-
                     // Bind data from CSV record with model classes
                     factory.bind(result, model, count);
 
@@ -209,38 +205,6 @@
public class BindyCsvDataFormat extends BindyAbstractDataFormat {
 
     }
 
-    /**
-     * Concatenate "the rest of the line" as the last record. Works similar as if quoted
-     *
-     * @param result    input result set
-     * @param maxpos    position of maximum record
-     * @param separator csv separator char
-     * @return List<String> with concatenated last record
-     */
-    private static List<String> autospanLine(final List<String> result, final int maxpos, final String separator) {
-        if (result.size() <= maxpos) {
-            return result;
-        }
-
-        final List<String> answer = new ArrayList<String>();
-        final StringBuilder lastRecord = new StringBuilder();
-
-        final Iterator<String> it = result.iterator();
-        for (int counter = 0; counter < maxpos - 1; counter++) {
-            answer.add(it.next());
-        }
-
-        while (it.hasNext()) {
-            lastRecord.append(it.next());
-            if (it.hasNext()) {
-                lastRecord.append(separator);
-            }
-        }
-        answer.add(lastRecord.toString());
-
-        return answer;
-    }
-
     /**
      * Unquote the tokens, by removing leading and trailing quote chars,
      * as will handling fixing broken tokens which may have been split
